var c = document.getElementById('game');
var ctx = c.getContext('2d');
var i;
function ranMap(a,b)
{
	var map;
	if(b==0)
	{
		do
		{
			map = Math.round(Math.random()*10);
		}
		while(map>9);
	}
	else
	{
		if(a==0)
		{
			do
			{
				map = Math.round(Math.random()*10);
			}
			while(map==2 || map==5 || map==8);
		}
		if(a==1)
		{
			do
			{
				map = Math.round(Math.random()*10);
			}
			while(map==4 || map==5 || map==7 || map==9);
		}
		if(a==2)
		{
			do
			{
				map = Math.round(Math.random()*10);
			}
			while(map==3 || map==6 || map==7);
		}
		if(a==3)
		{
			do
			{
				map = Math.round(Math.random()*10);
			}
			while(map==1 || map==6 || map==8 || map==9);
		}
	}
	return map;
}
// Background
var bg = new Array();
for(i=0;i<=9;i++)
{
	bg[i] = "BG/game"+i+".png";
}
var background = new Image();
background.onload = function()
{
	ctx.drawImage(background,0,0,800,600);
};
background.src = bg[ranMap(0,0)];
// Protagonist
Hero = function()
{
	var life = 3;
	var hside = new Array();
	hside[0] = "character/hero_u.png";
	hside[1] = "character/hero_d.png";
	hside[2] = "character/hero_l.png";
	hside[3] = "character/hero_r.png";
	var him = new Image();
	him.onload = function()
	{
		ctx.drawImage(him,400,300,100,100);
	};
	him.src = hside[1];
};
var prot = new Hero();